﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BO;
using Model;

namespace ZiChengCode
{
    public partial class FrmUserLoad_Oracle : Form
    {
        public FrmUserLoad_Oracle()
        {
            InitializeComponent();
            Init();
        }

        private void btn_TestContect_Click(object sender, EventArgs e)
        {
            OracleEntity.UserName = txtUserName.Text;
            OracleEntity.Password = txtUserPwd.Text;
            OracleEntity.ServicePath = txtServicePath.Text;
            if (string.IsNullOrEmpty(OracleEntity.ServicePath))
            {
                MessageBox.Show("服务不能为空!", "连接提醒");
                txtServicePath.Focus();
                return;
            }
            if (string.IsNullOrEmpty(OracleEntity.UserName))
            {
                MessageBox.Show("用户名不能为空!", "连接提醒");
                txtUserName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(OracleEntity.Password))
            {
                MessageBox.Show("密码不能为空!", "连接提醒");
                txtUserPwd.Focus();
                return;
            }
            var bo = new OracleBo();
            if (bo.Contect())
            {
                MessageBox.Show(new NativeWindow(), "连接成功", "连接提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                btn_OK.Enabled = true;
            }
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            OracleEntity.UserName = txtUserName.Text;
            OracleEntity.Password = txtUserPwd.Text;
            OracleEntity.ServicePath = txtServicePath.Text;
            OracleBo bo = new OracleBo();
            if (bo.Contect())
            {
                this.Hide();
                new FrmMain().ShowDialog();
            }
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void InitButton()
        {
            btn_TestContect.Enabled = true;
            btn_OK.Enabled = false;
        }
        private void Init()
        {
            txtServicePath.Text = "10.0.0.100/dev";
            txtUserName.Text = "bms_cms";
            txtUserPwd.Text = "bms_cms";
            InitButton();
        }

        private void FrmUserLoad_Oracle_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
